package com.yf.catcafe.service.impl;

import com.yf.catcafe.mapper.UserMapper;
import com.yf.catcafe.pojo.dto.UserInfoDto;
import com.yf.catcafe.pojo.dto.UserLoginDto;
import com.yf.catcafe.pojo.dto.UserRegisterDto;
import com.yf.catcafe.pojo.enity.User;
import com.yf.catcafe.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(UserLoginDto userLoginDto) {
        String username = userLoginDto.getUsername();
        String role = userLoginDto.getRole();
        User user=userMapper.getByUsernameandRole(username,role);
        return user;
    }

    @Override
    public User get(String username) {
        User user=userMapper.get(username);
        return user;
    }

    @Override
    public User getById(Long id) {
        User user=userMapper.getById(id);
        return user;
    }

    @Override
    public void update(UserInfoDto userInfoDto) {
        userMapper.update(userInfoDto);
    }

    @Override
    public void register(UserRegisterDto userRegisterDto) {
        userMapper.register(userRegisterDto);
    }
}
